home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5806 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.4 KB  |  77 lines

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: I need help on putting 2 strings together into 1(concatenate)
  5. Date: 20 Feb 1996 23:32:35 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Feb20163235@qcd.lanl.gov>
  8. References: <4gcr1b$ft3@cloner4.netcom.com>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: spdcool@ix.netcom.com's message of 20 Feb 1996 15:57:31 GMT
  13.  
  14. In article <4gcr1b$ft3@cloner4.netcom.com> spdcool@ix.netcom.com(SPD)
  15. writes: 
  16. <snip>
  17.    struct data {
  18.        char *full_name;
  19.        int age;
  20.        float salary;
  21.     };
  22.  
  23.    struct name  {
  24.       char *first1, *last1;
  25.      };
  26. <snip>
  27.      struct name fname[3], lname[3];
  28.      struct data secret[5];
  29. <snip>
  30.      fname[o].first1 = "Joe";
  31.  
  32. That o is presumably 0. So, your fname[0].first1 points to a region of
  33. unmodifiable memory 4 characters long containing the characters 'J'
  34. 'o' 'e' and '\0'.
  35.  
  36. <snip>
  37.      lname[0].last1 = "Jordan";
  38.  
  39. I guess you known what this means now.
  40.  
  41. <snip>
  42.       secret[i].full_name = fname[e].first1;/* the trouble some part begin
  43.  
  44. I hope the comment actually ends. So secret[i].full_name points to the
  45. same place as fname[e].first1, which if e is 0 means "a region of
  46. unmodifiable memory 4 characters long containing the characters 'J'
  47. 'o' 'e' and '\0'".
  48.  
  49. <snip>
  50.       strcat(secret[i].full_name," ");
  51.  
  52. This means find the first '\0' in what secret[i].full_name points to,
  53. overwrite that with ' ' and overwrite the next location with '\0'.
  54.  
  55. Ooops! it was pointing to a region which was unmodifiable, and there
  56. was no location reserved for it beyond the '\0'. Disaster!
  57.  
  58. <snip>
  59.      please e-mail me at spdcool@ix.netcom.com and spd7398@acf4.nyu.edu
  60.      mail me at both places b/c I may be at home or in school   
  61.  
  62. Please read the answer here.
  63.  
  64. I leave it as an excercise to figure out how to correct it. With what
  65. I told you, the faq, the routines malloc and strlen, you should be
  66. able to do the rest?
  67.  
  68. Cheers
  69. Tanmoy
  70. --
  71. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  72. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  73. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  74. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  75. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  76. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  77.